package com.training1.core.modules.service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.training1.core.common.service.CrudService;
import com.training1.core.common.utils.excel.ExcelUtil;
import com.training1.core.entity.BatchWithDrawalEntity;
import com.training1.core.modules.dao.RemitDao;

@Service
@Transactional
public class RemitService extends CrudService<RemitDao, BatchWithDrawalEntity> {
	/**
	 * 批量更新
	 * 
	 * @param map
	 * @return
	 */
	public int updateStatus(Map<String, Object> map) {
		return dao.updateStatus(map);

	}

	public BatchWithDrawalEntity findAllMoney(Map<String, Object> map) {
		return dao.findAllMoney(map);
	}

	public void export(List<BatchWithDrawalEntity> list, HttpServletResponse resp) {
		// 设置列标题
		List<String> excelHead = new ArrayList<String>();
		excelHead.add("订单编号");
		excelHead.add("会员手机号");
		excelHead.add("审核时间");
		excelHead.add("银行");
		excelHead.add("卡号");
		excelHead.add("持卡人姓名");
		excelHead.add("预留手机号");
		excelHead.add("申请金额");

		// 设置内容
		List<List<String>> dataList = new ArrayList<List<String>>();
		for (BatchWithDrawalEntity bde : list) {
			List<String> data = new ArrayList<String>();
			data.add(bde.getOrderNumber());
			data.add(bde.getPhone());

			Date date = bde.getAuditorTime();
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String dateString = formatter.format(date);
			data.add(dateString);

			data.add(bde.getBankforCard());
			data.add(bde.getCardNumber());
			data.add(bde.getName());
			data.add(bde.getCellphoneForCard());
			data.add(bde.getMoney().toString());

			dataList.add(data);
		}

		// 设置文件名
		String fileName;
		String sheetName = "sheet1";
		String titleName;
		fileName = "提现记录-待打款_" + new SimpleDateFormat("yyyy-MM-dd").format(new Date());
		titleName = "提现记录—待打款列表";

		ExcelUtil.exportExcel(resp, excelHead, dataList, fileName, sheetName, titleName);

	}

}
